<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Minimize sidelobe level of an array with arbitrary 2-D geometry</title>
<link rel="canonical" href="http://cvxr.com/cvx/examples/antenna_array_design/html/ant_array_min_sidelobe.html">
<link rel="stylesheet" href="../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Minimize sidelobe level of an array with arbitrary 2-D geometry</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#plots">Plots</a>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% "Convex optimization examples" lecture notes (EE364) by S. Boyd</span>
<span class="comment">% "Antenna array pattern synthesis via convex optimization"</span>
<span class="comment">% by H. Lebret and S. Boyd</span>
<span class="comment">% (figures are generated)</span>
<span class="comment">%</span>
<span class="comment">% Designs an antenna array such that:</span>
<span class="comment">% - it minimizes sidelobe level outside the beamwidth of the pattern</span>
<span class="comment">% - it has a unit sensitivity at some target direction</span>
<span class="comment">% - it has nulls (zero sensitivity) at specified direction(s) (optional)</span>
<span class="comment">%</span>
<span class="comment">% This is a convex problem (after sampling it can be formulated as an SOCP).</span>
<span class="comment">%</span>
<span class="comment">%   minimize   max |y(theta)|     for theta outside the beam</span>
<span class="comment">%       s.t.   y(theta_tar) = 1</span>
<span class="comment">%              y(theta_null) = 0  (optional)</span>
<span class="comment">%</span>
<span class="comment">% where y is the antenna array gain pattern (complex function) and</span>
<span class="comment">% variables are w (antenna array weights or shading coefficients).</span>
<span class="comment">% Gain pattern is a linear function of w: y(theta) = w'*a(theta)</span>
<span class="comment">% for some a(theta) describing antenna array configuration and specs.</span>
<span class="comment">%</span>
<span class="comment">% Written for CVX by Almir Mutapcic 02/02/06</span>

<span class="comment">% select array geometry</span>
ARRAY_GEOMETRY = <span class="string">'2D_RANDOM'</span>;
<span class="comment">% ARRAY_GEOMETRY = '1D_UNIFORM_LINE';</span>
<span class="comment">% ARRAY_GEOMETRY = '2D_UNIFORM_LATTICE';</span>

<span class="comment">% select if the optimal array pattern should enforce nulls or not</span>
HAS_NULLS = 0; <span class="comment">% HAS_NULLS = 1;</span>

<span class="comment">%********************************************************************</span>
<span class="comment">% problem specs</span>
<span class="comment">%********************************************************************</span>
lambda = 1;           <span class="comment">% wavelength</span>
theta_tar = 60;       <span class="comment">% target direction (should be an integer -- discretization)</span>
half_beamwidth = 10;  <span class="comment">% half beamwidth around the target direction</span>

<span class="comment">% angles where we want nulls (optional)</span>
<span class="keyword">if</span> HAS_NULLS
  theta_nulls = [95 110 120 140 225];
<span class="keyword">end</span>

<span class="comment">%********************************************************************</span>
<span class="comment">% random array of n antenna elements</span>
<span class="comment">%********************************************************************</span>
<span class="keyword">if</span> strcmp( ARRAY_GEOMETRY, <span class="string">'2D_RANDOM'</span> )
  <span class="comment">% set random seed to repeat experiments</span>
  rand(<span class="string">'state'</span>,0);

  <span class="comment">% (uniformly distributed on [0,L]-by-[0,L] square)</span>
  n = 40;
  L = 5;
  loc = L*rand(n,2);
  angleRange = 360;

<span class="comment">%********************************************************************</span>
<span class="comment">% uniform 1D array with n elements with inter-element spacing d</span>
<span class="comment">%********************************************************************</span>
<span class="keyword">elseif</span> strcmp( ARRAY_GEOMETRY, <span class="string">'1D_UNIFORM_LINE'</span> )
  <span class="comment">% (unifrom array on a line)</span>
  n = 30;
  d = 0.45*lambda;
  loc = [d*[0:n-1]' zeros(n,1)];
  angleRange = 180;

<span class="comment">%********************************************************************</span>
<span class="comment">% uniform 2D array with m-by-m element with d spacing</span>
<span class="comment">%********************************************************************</span>
<span class="keyword">elseif</span> strcmp( ARRAY_GEOMETRY, <span class="string">'2D_UNIFORM_LATTICE'</span> )
  m = 6; n = m^2;
  d = 0.45*lambda;

  loc = zeros(n,2);
  <span class="keyword">for</span> x = 0:m-1
    <span class="keyword">for</span> y = 0:m-1
      loc(m*y+x+1,:) = [x y];
    <span class="keyword">end</span>
  <span class="keyword">end</span>
  loc = loc*d;
  angleRange = 360;

<span class="keyword">else</span>
  error(<span class="string">'Undefined array geometry'</span>)
<span class="keyword">end</span>

<span class="comment">%********************************************************************</span>
<span class="comment">% construct optimization data</span>
<span class="comment">%********************************************************************</span>
<span class="comment">% build matrix A that relates w and y(theta), ie, y = A*w</span>
theta = [1:angleRange]';
A = kron(cos(pi*theta/180), loc(:,1)') + kron(sin(pi*theta/180), loc(:,2)');
A = exp(2*pi*i/lambda*A);

<span class="comment">% target constraint matrix</span>
[diff_closest, ind_closest] = min( abs(theta - theta_tar) );
Atar = A(ind_closest,:);

<span class="comment">% nulls constraint matrix</span>
<span class="keyword">if</span> HAS_NULLS
  Anull = []; ind_nulls = [];
  <span class="keyword">for</span> k = 1:length(theta_nulls)
    [diff_closest, ind_closest] = min( abs(theta - theta_nulls(k)) );
    Anull = [Anull; A(ind_closest,:)];
    ind_nulls = [ind_nulls ind_closest];
  <span class="keyword">end</span>
<span class="keyword">end</span>

<span class="comment">% stopband constraint matrix</span>
ind = find(theta &lt;= (theta_tar-half_beamwidth) | <span class="keyword">...</span>
           theta &gt;= (theta_tar+half_beamwidth) );
<span class="keyword">if</span> HAS_NULLS, ind = setdiff(ind,ind_nulls); <span class="keyword">end</span>;
As = A(ind,:);

<span class="comment">%********************************************************************</span>
<span class="comment">% optimization problem</span>
<span class="comment">%********************************************************************</span>
cvx_begin
  variable <span class="string">w(n)</span> <span class="string">complex</span>
  minimize( max( abs(As*w) ) )
  subject <span class="string">to</span>
    Atar*w == 1;   <span class="comment">% target constraint</span>
    <span class="keyword">if</span> HAS_NULLS   <span class="comment">% nulls constraints</span>
      Anull*w == 0;
    <span class="keyword">end</span>
cvx_end

<span class="comment">% check if problem was successfully solved</span>
disp([<span class="string">'Problem is '</span> cvx_status])
<span class="keyword">if</span> ~strfind(cvx_status,<span class="string">'Solved'</span>)
  <span class="keyword">return</span>
<span class="keyword">end</span>

min_sidelobe_level = 20*log10( max(abs(As*w)) );
fprintf(1,<span class="string">'The minimum sidelobe level is %3.2f dB.\n\n'</span>,<span class="keyword">...</span>
          min_sidelobe_level );

<span class="comment">%********************************************************************</span>
<span class="comment">% plots</span>
<span class="comment">%********************************************************************</span>
figure(1), clf
plot(loc(:,1),loc(:,2),<span class="string">'o'</span>)
title(<span class="string">'Antenna locations'</span>)

<span class="comment">% plot array pattern</span>
<span class="keyword">if</span> angleRange == 180,
    theta = [1:360]';
    A = [ A; -A ];
<span class="keyword">end</span>
y = A*w;
figure(2), clf
ymin = floor(0.1*min_sidelobe_level)*10-10; ymax = 0;
plot([1:360], 20*log10(abs(y)), <span class="keyword">...</span>
     [theta_tar theta_tar],[ymin ymax],<span class="string">'r--'</span>,<span class="keyword">...</span>
     [theta_tar+half_beamwidth theta_tar+half_beamwidth],[ymin ymax],<span class="string">'g--'</span>,<span class="keyword">...</span>
     [theta_tar-half_beamwidth theta_tar-half_beamwidth],[ymin ymax],<span class="string">'g--'</span>);
<span class="keyword">if</span> HAS_NULLS <span class="comment">% add lines that represent null positions</span>
  hold <span class="string">on</span>;
  <span class="keyword">for</span> k = 1:length(theta_nulls)
    plot([theta_nulls(k) theta_nulls(k)],[ymin ymax],<span class="string">'m--'</span>);
  <span class="keyword">end</span>
  hold <span class="string">off</span>;
<span class="keyword">end</span>
xlabel(<span class="string">'look angle'</span>), ylabel(<span class="string">'mag y(theta) in dB'</span>);
axis([0 360 ymin ymax]);

<span class="comment">% polar plot</span>
figure(3), clf
zerodB = -ymin;
dBY = 20*log10(abs(y)) + zerodB;
ind = find( dBY &lt;= 0 ); dBY(ind) = 0;
plot(dBY.*cos(pi*theta/180), dBY.*sin(pi*theta/180), <span class="string">'-'</span>);
axis([-zerodB zerodB -zerodB zerodB]), axis(<span class="string">'off'</span>), axis(<span class="string">'square'</span>)
hold <span class="string">on</span>
plot(zerodB*cos(pi*theta/180),zerodB*sin(pi*theta/180),<span class="string">'k:'</span>) <span class="comment">% 0 dB</span>
plot( (min_sidelobe_level + zerodB)*cos(pi*theta/180), <span class="keyword">...</span>
      (min_sidelobe_level + zerodB)*sin(pi*theta/180),<span class="string">'k:'</span>)  <span class="comment">% min level</span>
text(-zerodB,0,<span class="string">'0 dB'</span>)
tt = text(-(min_sidelobe_level + zerodB),0,sprintf(<span class="string">'%0.1f dB'</span>,min_sidelobe_level));
set(tt,<span class="string">'HorizontalAlignment'</span>,<span class="string">'right'</span>);
theta_1 = theta_tar+half_beamwidth;
theta_2 = theta_tar-half_beamwidth;
plot([0 55*cos(theta_tar*pi/180)], [0 55*sin(theta_tar*pi/180)], <span class="string">'k:'</span>)
plot([0 55*cos(theta_1*pi/180)], [0 55*sin(theta_1*pi/180)], <span class="string">'k:'</span>)
plot([0 55*cos(theta_2*pi/180)], [0 55*sin(theta_2*pi/180)], <span class="string">'k:'</span>)
<span class="keyword">if</span> HAS_NULLS <span class="comment">% add lines that represent null positions</span>
  <span class="keyword">for</span> k = 1:length(theta_nulls)
    plot([0 55*cos(theta_nulls(k)*pi/180)], <span class="keyword">...</span>
         [0 55*sin(theta_nulls(k)*pi/180)], <span class="string">'k:'</span>)
  <span class="keyword">end</span>
<span class="keyword">end</span>
hold <span class="string">off</span>
</pre>
<a id="output"></a>
<pre class="codeoutput">
 
Calling sedumi: 1366 variables, 422 equality constraints
   For improved efficiency, sedumi is solving the dual problem.
------------------------------------------------------------
SeDuMi 1.21 by AdvOL, 2005-2008 and Jos F. Sturm, 1998-2003.
Alg = 2: xz-corrector, Adaptive Step-Differentiation, theta = 0.250, beta = 0.500
Put 2 free variables in a quadratic cone
eqs m = 422, order n = 1026, dim = 1368, blocks = 343
nnz(A) = 55743 + 0, nnz(ADA) = 62144, nnz(L) = 31283
 it :     b*y       gap    delta  rate   t/tP*  t/tD*   feas cg cg  prec
  0 :            2.29E+02 0.000
  1 :  -8.28E-01 1.31E+02 0.000 0.5712 0.9000 0.9000   3.26  1  1  2.2E+02
  2 :  -1.53E-01 1.00E+02 0.000 0.7640 0.9000 0.9000  15.87  1  1  2.5E+01
  3 :  -9.46E-02 7.23E+01 0.000 0.7217 0.9000 0.9000   5.45  1  1  9.7E+00
  4 :  -8.27E-02 4.22E+01 0.000 0.5836 0.9000 0.9000   2.24  1  1  4.3E+00
  5 :  -8.03E-02 2.20E+01 0.000 0.5222 0.9000 0.9000   1.56  1  1  2.0E+00
  6 :  -7.57E-02 8.92E+00 0.000 0.4053 0.9000 0.9000   1.33  1  1  7.2E-01
  7 :  -7.40E-02 4.95E+00 0.000 0.5545 0.9000 0.9000   1.13  1  1  3.9E-01
  8 :  -7.26E-02 2.75E+00 0.000 0.5567 0.9000 0.9000   1.08  1  1  2.1E-01
  9 :  -7.14E-02 1.21E+00 0.000 0.4401 0.9000 0.9000   1.04  1  1  9.3E-02
 10 :  -7.06E-02 2.35E-01 0.000 0.1942 0.9224 0.9000   1.01  1  1  2.1E-02
 11 :  -7.04E-02 7.36E-02 0.000 0.3127 0.9046 0.9000   1.00  1  1  6.9E-03
 12 :  -7.03E-02 2.76E-02 0.000 0.3747 0.9015 0.9000   1.00  1  1  2.6E-03
 13 :  -7.03E-02 5.69E-03 0.000 0.2063 0.9000 0.0000   1.00  1  1  7.6E-04
 14 :  -7.03E-02 6.05E-04 0.000 0.1063 0.9123 0.9000   1.00  2  2  1.1E-04
 15 :  -7.03E-02 8.09E-05 0.000 0.1337 0.9132 0.9000   1.00  2  2  1.8E-05
 16 :  -7.03E-02 1.82E-05 0.000 0.2256 0.9196 0.9000   1.00  5  5  5.1E-06
 17 :  -7.03E-02 5.29E-06 0.000 0.2900 0.9155 0.9000   1.00  4  7  1.7E-06
 18 :  -7.03E-02 1.22E-06 0.000 0.2303 0.9086 0.9000   1.00 15 15  4.5E-07
 19 :  -7.03E-02 1.78E-07 0.000 0.1460 0.9062 0.9000   1.00 22 50  7.6E-08
 20 :  -7.03E-02 3.25E-08 0.000 0.1824 0.9010 0.9000   1.00 69 99  1.4E-08

iter seconds digits       c*x               b*y
 20      0.7   8.7 -7.0302086004e-02 -7.0302086150e-02
|Ax-b| =   1.1e-08, [Ay-c]_+ =   2.7E-09, |x|=  5.7e-01, |y|=  1.1e+02

Detailed timing (sec)
   Pre          IPM          Post
8.000E-02    6.800E-01    1.000E-02    
Max-norms: ||b||=1, ||c|| = 1,
Cholesky |add|=38, |skip| = 2, ||L.L|| = 3566.47.
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +0.0703021
Problem is Solved
The minimum sidelobe level is -23.06 dB.

</pre>
<a id="plots"></a>
<div id="plotoutput">
<img src="ant_array_min_sidelobe__01.png" alt=""> <img src="ant_array_min_sidelobe__02.png" alt=""> <img src="ant_array_min_sidelobe__03.png" alt=""> 
</div>
</div>
</body>
</html>